<template>
  <div class="app-container">
    <div class="head-container">
      <el-input v-model="query.value" clearable placeholder="全表模糊搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="handleQuery"/>
      <el-button size="mini" type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
    </div>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="mini" :height="tableHeight" style="width: 100%;" border fit>
      <el-table-column prop="username" label="用户名" align="center"/>
      <el-table-column prop="deptName" label="岗位" align="center"/>
      <el-table-column prop="ip" label="登录IP" align="center"/>
      <el-table-column show-overflow-tooltip prop="address" label="登录地点" align="center"/>
      <el-table-column prop="browser" label="浏览器" align="center"/>
      <el-table-column prop="os" label="操作系统" align="center"/>
      <el-table-column prop="loginTime" label="登录时间" align="center">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loginTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="操作" align="center">
        <template slot-scope="scope">
          <el-button slot="reference" size="mini"  type="text" v-permissions="['monitor:online:forceLogout']" @click="handleDelete(scope.row.key)">强退</el-button>
          <!-- <el-popover  v-permission="['admin']" :ref="scope.$index" placement="top"  width="180">
            <p>确定踢出该用户吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.$index].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.$index, scope.row.key)">确定</el-button>
            </div>

          </el-popover> -->
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination :total="total" :current-page="page + 1" style="margin-top: 8px;" layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"  @current-change="pageChange"/>
  </div>
</template>

<script>
import initData from '@/mixins/initData'
import { parseTime } from '@/utils/index'
import tableHeight from '@/mixins/tableHeight'
import { forceLogout } from '@/api/base/online'
export default {
  name: 'OnlineUser',
  mixins: [initData, tableHeight],
  data () {
    return {
      delLoading: false
    }
  },
  created () {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    beforeInit () {
      this.url = 'api/monitor/online/page'
      this.page = 0
      return true
    },
    handleQuery () {
      this.page = 0
      this.init()
    },
    handleDelete (key) {
      this.delLoading = true
      forceLogout(key).then(res => {
        this.init()
        this.$notify({
          title: '踢出成功',
          type: 'success',
          duration: 2500
        })
      })
    }
  }
}
</script>
